package cn.wd.web.controller;

import cn.wd.domain.BulletMsg;
import cn.wd.page.PageResult;
import cn.wd.qo.BulletMsgQueryObject;
import cn.wd.service.IBulletMsgService;
import cn.wd.vo.JsonResult;
import cn.wd.vo.ReportBulletMsg;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/bulletMsg")
public class BulletMsgController {
    
    private final IBulletMsgService bulletMsgService;

    public BulletMsgController(IBulletMsgService bulletMsgService) {
        this.bulletMsgService = bulletMsgService;
    }

    @RequestMapping("/list")
    public JsonResult<PageResult<BulletMsg>> list(BulletMsgQueryObject qo) {
        return JsonResult.success(bulletMsgService.query(qo));
    }

    // 举报弹幕
    @RequestMapping("/reportBulletMsg")
    public JsonResult<?> saveOrUpdate(@RequestBody ReportBulletMsg reportBulletMsg) {
        bulletMsgService.reportBulletMsg(reportBulletMsg);
        return JsonResult.success();
    }

    @RequestMapping("/saveOrUpdate")
    public JsonResult<?> saveOrUpdate(@RequestBody BulletMsg bulletMsg) {
        if (bulletMsg.getId() != null) {
            bulletMsgService.updateById(bulletMsg);
        } else {
            bulletMsg.setVideoTime(new Date());
            bulletMsg.setReleaseTime(new Date());
            bulletMsgService.save(bulletMsg);
        }
        return JsonResult.success();
    }

    @RequestMapping("/delete")
    public JsonResult<?> delete(Long id) {
        if (id == null) {
            return JsonResult.failed();
        }
        bulletMsgService.deleteById(id);
        return JsonResult.success();
    }
}
